package com.llp.declaresystem.controller;

import com.llp.declaresystem.domain.Result;
import com.llp.declaresystem.domain.entity.AdminUserView;
import com.llp.declaresystem.domain.entity.User;
import com.llp.declaresystem.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author llp
 * {@code @date} 2022年11月27日22:05
 * admin的用户信息管理
 */
@RestController
@Slf4j
@RequestMapping("/api/admin")
public class UserMessageController {
    @Autowired
    UserService userService;
    @Autowired
    UsergroupService usergroupService;
    @Autowired
    AdminService adminService;


    //获取用户列表
    @RequestMapping("/userList")
    public Result getUserList() {
        List<AdminUserView> list = userService.getAdminUserView();
        if (list != null) return new Result<>(200, "返回用户列表成功", list);
        else return new Result<>(400, "修改失败", null);
    }

    //添加用户
    @RequestMapping("/addUser")
    public Result addUser(@RequestBody User user) {
        System.out.println("user = " + user);
        boolean b = userService.addUser(user);
        if (b)  return new Result<>(200, "添加用户成功", null);
        return new Result<>(400,"添加用户失败",null);
    }
    //删除用户
    @RequestMapping("/deleteUser")
    public Result deleteUser(@RequestBody Map<String,Integer> map)
    {
      boolean b= adminService.deleteUser(map.get("uid"),map.get("gid"));
//        System.out.println("uid = " + map.get("uid"));
//        System.out.println("gid = " + map.get("gid"));
        if (b)  return new Result<>(200, "删除用户成功", null);
        return new Result<>(400,"删除用户失败",null);

    }
}
